<template>
	<view :class="currentTheme">
		<a-nabbar name="发货" />
		<view class="u-padding-32">
			<item-box :padding="16">
				<view class="u-padding-left-20 u-padding-right-20">
					<label-box label="快递单号" paddingTb="18">
						<view class="u-padding-left-20">
							<u-input placeholder="请输入快递单号" type="number" v-model="delivery.deliveryId" :clearable="false" border :borderColor="currentThemeObj.inputBorderColor" :placeholder-style="`color:${currentThemeObj.placeholderColor}`"></u-input>
						</view>
					</label-box>
					<label-box label="物流公司" paddingTb="18">
						<view class="u-padding-left-20">
							<select-item  :list="expressList" v-model="delivery.name" @getSelect="getSelect"></select-item>
						</view>
					</label-box>
				</view>
			</item-box>
		</view>
		<fixed-team btnText="确定"  @btnClick="submitExpress"></fixed-team>
	</view>
</template>

<script>
	import {getDetail,add} from '@/api/crud.js'
	export default {
		data() {
			return {
				apiModule:'shopApi',
				apiType:'storeOrder',
				delivery:{
					deliveryId:'',
					deliveryName:'',
					deliverySn:'',
					expressId:''
				},
				expressList:[],
				cartInfoId:''
				
			};
		},
		onLoad(option) {
			this.cartInfoId = option.cartInfoId
			//查询快递公司
			getDetail('','express',this.apiModule,'list').then(res=>{
				this.expressList = res.map(val=>({
					label:val.name,
					value:val.id,
					extra:val
				}));
			})
		},
		methods: {
			//获取选择的快递公司
			getSelect(item){
				const val = item[0].extra;
				this.delivery = {
					...this.delivery,
					deliveryName:val.name,
					deliverySn:val.code,
					expressId:val.id
				}
			},
			//点击发货
			submitExpress(){
				if(!this.delivery.deliveryId){
					this.$u.toast('请录入快递单号')
					return false;
				}
				if(!this.delivery.deliveryName){
					this.$u.toast('请选择快递公司')
					return false;
				}
				add(this.delivery,this.apiType,this.apiModule,`delivery/${this.cartInfoId}`).then(res=>{
					this.$u.toast('发货成功')
					setTimeout(()=>{
						this.$u.route({
							type:'back'
						})
					},1000)
				})
			},
		},
	}
</script>

<style lang="scss">

	.form-label{
		width: 210rpx;
		color: white;
		font-size: 32rpx;
	}
	.form-label-width{
		width: 170rpx;
		color: white;
		font-size: 32rpx;
	}
</style>
